<?php

declare(strict_types=1);


namespace App\Controller\Api;


use App\Constants\ErrorCode;
use App\Service\PrizeService;
use Hyperf\Di\Annotation\Inject;
use App\Controller\AbstractController;
use App\Utils\ApiUtils;



/**
 *
 */
class PrizeController extends AbstractController
{

    /**
     * @Inject
     * @var PrizeService
     */
    protected $prizeService;

    /**
     * 奖品列表
     * @return \Psr\Http\Message\ResponseInterface
     */
    public function list()
    {
        $result = $this->prizeService->list();
        return $this->response->json(ApiUtils::send(ErrorCode::SUCCESS,'获取成功',$result));
    }


    /**
     * 用户抽奖
     * @return \Psr\Http\Message\ResponseInterface
     */
    public function lottery()
    {
        $result = $this->prizeService->lottery();
        return $this->response->json(ApiUtils::send(ErrorCode::SUCCESS,'获取成功',$result));
    }

    /**
     * 抽奖记录
     * @return \Psr\Http\Message\ResponseInterface
     */
    public function lotteryLog()
    {
        $page = (int)$this->request->input('page', 1);
        $pageSize = (int)$this->request->input('pageSize', 15);
        $result = $this->prizeService->lotteryLog($page, $pageSize);
        return $this->response->json(ApiUtils::send(ErrorCode::SUCCESS,'获取成功',$result['data'], $result['count']));
    }

}
